<meta title="抢购商品"/>
<div class="p">
    <div class="m-b clearfix">
        <form class="form-inline pull-left" id="form">
            <input autocomplete="off" type="text" s="datetimepicker" class="form-control input-sm" placeholder="选择日期" style="width:120px;"
                   name="date"/>
            <select class="form-control input-sm" s="select"
                    s-select="{value: 'time'}"
                    s-build="S.get('/api/flashSaleItemSetting/seasonList')"
                    name="season">
                <option value="">场次</option>
            </select>
            <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
            <select class="form-control input-sm" s="select"
                    s-build="S.get('/api/enum/valuesMap/core.enums.FlashSaleItemStatus?igNames=DELETED')"
                    name="status">
                <option value="">状态</option>
            </select>
            <button type="button" class="btn btn-default btn-sm"
                    s-click="$page.node.val(1); $flashSaleItemsGrid.refresh()">查询
            </button>
        </form>
        <div class="pull-right">
            <div class="btn-group">
                <a href="javascript:;" class="btn btn-default btn-sm"
                   s-click="add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>
        </div>
    </div>
    <div id="flashSaleItemsGrid"
         s='datac,nda'
         s-data="S.get('/api/flashSaleItem/search', $form.node.serialize())">
        <table class="table table-striped table-bordered table-hover table-middle">
            <tr>
                <th>日期</th>
                <th>场次</th>
                <th style="width: 250px;">商品</th>
                <th>标签</th>
                <th>价格</th>
                <th>原价</th>
                <th>券值</th>
                <th>优惠券</th>
                <th>佣金</th>
                <th>返钱</th>
                <th>平台</th>
                <th>领取/数量</th>
                <th>创建时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop" s-data-filter="'results'">
            <tr s-loop-role="empty">
                <td colspan="15">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s-check-role="i" s="datac" class="flashSaleItem">
                <td name="date"></td>
                <td name="season"></td>
                <td s="tpl">
                    <a href="{%=this.item.couponClickUrl ? this.item.couponClickUrl : this.item.sourceItemUrl%}"
                       target="_blank" external>{%=this.item.title%}</a>
                    <div>
                        <label class="label label-warning" s-click="editSlogan(this)">{%=this.slogan || '标语'%}</label>
                    </div>
                </td>
                <td name="label"></td>
                <td name="item.price"></td>
                <td name="item.originPrice"></td>
                <td name="item.couponValue"></td>
                <td name="item.couponInfo"></td>
                <td s="tpl">
                    {%if(this.item.highCommission){%}
                    <label class="label label-warning">{%=this.item.commissionRate%}%</label>
                    {%}else{%}
                    <label class="label label-info">{%=this.item.commissionRate%}%</label>
                    {%}%}
                </td>
                <td name="item.returnFee"></td>
                <td name="item.ecomPlatTitle"></td>
                <td>
                    <span name="drawnNum"></span>/<span name="totalNum"></span>
                </td>
                <td name="createTime"></td>
                <td s="tpl">
                    {%if(this.status=='ONSALE'){%}
                    <label class="label label-success">{%=this.statusTitle%}</label>
                    {%}else{%}
                    <label class="label label-default">{%=this.statusTitle%}</label>
                    {%}%}
                </td>
                <td class="text-right" s="tpl">
                    {%if(this.status=='ONSALE'){%}
                    <a href="javascript:;" class="btn btn-warning btn-xs btn-outline" s-click="setStatus(this, 'INSTOCK')">下架</a>
                    {%}else{%}
                    <a href="javascript:;" class="btn btn-danger btn-xs btn-outline" s-click="setStatus(this, 'DELETED')">删除</a>
                    <a href="javascript:;" class="btn btn-success btn-xs btn-outline" s-click="setStatus(this, 'ONSALE')">上架</a>
                    {%}%}
                    <a href="javascript:;" class="btn btn-info btn-xs btn-outline" s-click="doRemind(this)">提醒</a>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-default" value="编辑" s-click="edit(this)"/>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="15" class="text-right">
                    <ul s="pagination"
                        s-pagination="{action:function(){$page.node.val(this); $flashSaleItemsGrid.refresh()}}"
                        class="pagination pagination-sm">
                    </ul>
                    共有<span name="total"></span>个数据
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">

    function setStatus($this, status) {
        S.confirm("确定操作吗？").done(function () {
            S.put("/api/flashSaleItem/status/" + $this.parent().data().id + '-' + status).done(function () {
                $flashSaleItemsGrid.refresh();
            })
        })
    }

    function doRemind($this) {
        S.confirm("确定操作吗？").done(function () {
            S.put("/api/flashSaleItem/remind/" + $this.parent().data().id).done(function () {
                S.toast('操作成功', 'success')
            })
        })
    }

    function add() {
        S.popupOpen('/commission-item/commission-item-selector.html').done(function(itemList) {
            if(itemList && itemList.length) {
                S.post("/api/commissionItem/fetch", {
                    itemList: JSON.stringify(itemList)
                }).done(function(_itemList) {
                    S.popupOpen('/flashSaleItem/flashSaleItem-add.html', {itemList: _itemList}).done(function(rs) {
                        $flashSaleItemsGrid.refresh();
                    })
                })
            }
        })
    }

    function editSlogan($this) {
        var row = $this.parent()
        var data = row.data()
        S.popupOpen('/flashSaleItem/edit-slogan.html', {flashSaleItem: data}).done(function(rs) {
            $this.node.html(rs)
        })
    }

    //编辑
    function edit($this) {
       /* var data = $this.parent().data().id;*/
        var data = $this.parent().data();
        S.popupOpen('/flashSaleItem/flashSaleItem-edit.html', {flashSaleItemedit: data}).done(function(rs) {
            rs && $flashSaleItemsGrid.refresh();
        })
    }
</script>